﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace SQ816FWUpdater
{
    // A simple wrapper to launch a command line process
    class CmdLineWrapper
    {
        string Program;
        string Args;
        public Process Proc { get; private set; }

        public StreamReader StdOut { get { return Proc.StandardOutput; } }
        public StreamReader StdErr { get { return Proc.StandardError; } }
        public int ExitCode { get { return Proc.ExitCode; } }

        public CmdLineWrapper(string program, IEnumerable<string> args)
        {
            Program = program;
            Args = string.Join(" ", args);
        }
        public CmdLineWrapper(string program, params string[] args)
            : this(program, args.AsEnumerable<string>()) { }
        public bool Run()
        {
            try
            {
                ProcessStartInfo psi = new ProcessStartInfo(Program, Args);
                psi.CreateNoWindow = true;
                psi.RedirectStandardOutput = true;
                psi.RedirectStandardError = true;
                psi.UseShellExecute = false;
                Proc = Process.Start(psi);
                return true;
            }
            catch { return false; }
        }
    }
}
